<?php

if($_POST['act'] && $_POST['act']=='savePrice'){//保存起免价格
    if($_POST['id'] && $_POST['id']>0){
        if(isset($_POST['free_shipping_price'])){
            $sql = "update ".FREESHIPEXPRESS." set free_shipping_price='{$_POST['free_shipping_price']}' where id={$_POST['id']}";
            $db->query($sql);
        }
    }
    die();
}
if($_POST['act'] && $_POST['act']=='saveFee'){//保存减免价格
    if($_POST['id'] && $_POST['id']>0){
        if($_POST['free_shipping_price'] && $_POST['free_shipping_price']>0){
            $sql = "update ".FREESHIPEXPRESS." set free_fee='{$_POST['free_shipping_price']}' where id={$_POST['id']}";
            $db->query($sql);
        }
    }
    die();
}
if($_POST['act'] && $_POST['act']=='changeStatus'){//改变状态
    if($_POST['id'] && $_POST['id']>0){
        $sql = "update ".FREESHIPEXPRESS." set `status`='{$_POST['status']}' where id={$_POST['id']}";
        $db->query($sql);
    }
    die();
}

include_once("../includes/page_utf_class.php");
include_once("../module/product/includes/plugin_order_class.php");
$order = new order;
//----------------------分仓
$general_shop =$order->get_general_shop();

if ($general_shop!=0&&$general_shop!=$_GET['stock_shop']&&isset($_GET['stock_shop'])){
    msg('noright.php');
    exit;
}
$str = "";
if ($general_shop){
    $_GET['stock_shop'] =$general_shop;
}
if ($_GET['stock_shop']){
    $str.=" and a.stock_shop = '$_GET[stock_shop]' ";
}
//-----------------

if(isset($_GET['status']) && $_GET['status']!=''){
    $str.=" and a.status='{$_GET['status']}'";
}

$sql = "select a.*,b.title as express_name from ".FREESHIPEXPRESS." a left join ".LGSTEMP." b on b.id=a.express_id where b.status>0 {$str} ";

$page = new Page;
$page->listRows=20;
if (!$page->__get('totalRows')){
    $db->query($sql);
    $de['count']=$page->totalRows = $db->num_rows();
}
$de['count']=$de['count']?$de['count']:$_GET['totalRows'];
$sql .= "  limit ".$page->firstRow.",".$page->listRows;
$de['page'] = $page->prompt();

$db->query($sql);
$ss=$db->getRows();

//----------------------分仓
$stock_shops=$order->get_stock_shops();
$tpl->assign("stock_shops",$stock_shops);
$tpl->assign("general_shop",$general_shop);
//-----------------------------

$shop_temp = array();
foreach ($stock_shops as $sv)
{
    $shop_temp[$sv['id']] = $sv['title'];
}

foreach($ss as $k)
{
    $k['shop_name']=$shop_temp[$k['stock_shop']];
    $list[]=$k;
}
$de["list"]=$list;

$tpl->assign('de',$de);
$tpl->assign('config',$config);
$tpl->display('free_shipping_express.htm');
?>